package acwing.模拟;

import java.util.Scanner;

/**
 * 分糖果
 *
 * @author yang
 * @date 2021/12/14
 */
public class 分糖果 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        while (true) {

            int t = arr[0];
            for (int i = 0; i <= n - 2;i++) {
                arr[i] /= 2;
                arr[i] += arr[i + 1] / 2;
                if ((arr[i] & 1) == 1) {
                    arr[i]++;
                    ans++;
                }
            }

            arr[n - 1] /= 2;
            arr[n - 1] += t / 2;
            if ((arr[n - 1] & 1) == 1) {
                arr[n - 1]++;
                ans++;
            }
            if (check(arr)) {
                System.out.println(ans);
                return;
            }
        }
    }

    private static boolean check(int[] arr) {
        int t = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] != t) return false;
        }
        return true;
    }
}
